package com.example.itcompanyinterview.tools;

import com.example.itcompanyinterview.R;

import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class TitleBarGenerator {
	private Activity activity;
	private String titleText;
	private String actionText;
	private int returnButtonView = View.VISIBLE;
	private int actionButtonView = View.VISIBLE;
	
	public TitleBarGenerator(Activity context) {
		this.activity = context;
	}
	
	public void showTitleBar() {
		this.activity.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.app_title);
        TextView appTitleView = (TextView)this.activity.findViewById(R.id.activity_title);    	
     	appTitleView.setText(titleText);
     	
     	ImageView returnButton = (ImageView)this.activity.findViewById(R.id.title_return_button);
     	returnButton.setVisibility(returnButtonView);
     	this.addDefaultReturnAction();
     	
     	Button actionButton = (Button)this.activity.findViewById(R.id.title_action_button);
     	actionButton.setText(actionText);
     	actionButton.setVisibility(actionButtonView);	
    }
	
	public void changeTitleText(String title) {
		this.titleText = title;
		TextView appTitleView = (TextView)this.activity.findViewById(R.id.activity_title);    	
     	appTitleView.setText(this.titleText);
	}
	
	private void addDefaultReturnAction() {
		ImageView returnButton = (ImageView)this.activity.findViewById(R.id.title_return_button);
		returnButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				activity.finish();
			}
		});
	}
	

	public int getReturnButtonView() {
		return returnButtonView;
	}

	public TitleBarGenerator setReturnButtonView(int returnButtonView) {
		this.returnButtonView = returnButtonView;
		return this;
	}

	public int getActionButtonView() {
		return actionButtonView;
	}

	public TitleBarGenerator setActionButtonView(int actionButtonView) {
		this.actionButtonView = actionButtonView;
		return this;
	}

	public String getTitleText() {
		return titleText;
	}

	public TitleBarGenerator setTitleText(String titleText) {
		this.titleText = titleText;
		return this;
	}

	public String getActionText() {
		return actionText;
	}

	public TitleBarGenerator setActionText(String actionText) {
		this.actionText = actionText;
		return this;
	}
	
}
